<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="test"></div>
	
	<!-- 引入react核心库 -->
	<script type="text/javascript" src="../js/react.development.js"></script>
	<!-- 引入react-dom，用于支持react操作DOM -->
	<script type="text/javascript" src="../js/react-dom.development.js"></script>
	<!-- 引入babel，用于将jsx转为js -->
	<script type="text/javascript" src="../js/babel.min.js"></script>
	<!-- 引入prop-types，用于对组件标签属性进行限制 -->
	<script type="text/javascript" src="../js/prop-types.js"></script>

	<script type="text/babel">
        class Demo extends React.Component{
            state = {isHot:true};
            showData = ()=>{
                const {input1} = this;
                console.log(input1.value);
            }
            showData2 = (event)=>{
                console.log(event.target.value);
            }
            changeWeather =()=>{
                const {isHot} = this.state;
                this.setState({
                    isHot:!isHot,
                })
            }
            saveInput = (currentNode)=>{
                this.input1 = currentNode;
            }
            render(){
                const {isHot} = this.state;
                // 回调形式的ref，收到一个参数即当前节点，把这个节点赋值到this对象上
                // 后续使用的时候直接从this对象上解构出来即可
                return (
                    <div>
                        <h1 onClick={this.changeWeather}>今天天气很{isHot?'炎热':'凉爽'}</h1>
                        {/*<input ref={currentNode => this.input1 = currentNode} type="text" placeholder="点击按钮提示数据"/>*/}
                        <input ref={this.saveInput} type="text" placeholder="点击按钮提示数据"/>
                        <button ref="button" onClick={this.showData}>点我提示左侧的数据</button>
                        <input onBlur={this.showData2} type="text" placeholder="失去焦点提示数据"/>
                    </div>
                )
            }
        }
        ReactDOM.render(<Demo/>,document.getElementById('test'));
    </script>
</body>
</html>